<template>
  <div class="gallery-view">
    <TopTitle name="图库" :is-search="true" @search="search" class="gallery-view__header" />

    <div class="gallery-view__filters" v-show="!query">
      <subsetView :classify="1" @nowSubset="nowSelect"></subsetView>
    </div>

    <div class="gallery-view__main">
      <galleryComponent :subsetId="nowSubset" :serchTerm="serchTerm">
      </galleryComponent>
    </div>
  </div>
</template>

<script setup lang="ts">
import TopTitle from '@/components/bar/TopTitle.vue';
import subsetView from '@/components/subset/subsetView.vue';
import galleryComponent from '@/components/gallery/galleryComponent.vue';
import { ref } from 'vue';


const nowSubset = ref<number | string>(-1); // 当前分组ID

const nowSelect = (e: { id: number | string; type: string }) => {
  if (e.type === 'all') {
    nowSubset.value = -1;
  } else if (e.type === 'subset' || e.type === 'exclude') {
    nowSubset.value = e.id;
  }
}

// 搜索

const serchTerm = ref<string>('')
const query = ref<boolean>(false)
const search = (e: string) => {
  serchTerm.value = e
  if (e) {
    query.value = true
  } else {
    query.value = false
  }
}
</script>

<style scoped lang="less">
// 颜色变量
@primary-color: #3a7bd5;
@primary-light: rgba(58, 123, 213, 0.07);
@text-color: #2c3e50;
@text-light: #5e6c84;
@bg-color: #ffffff;
@bg-light: #f9fafc;
@border-color: #edf0f5;
@container-width: 1280px;
@transition-time: 0.3s;
@transition-ease: cubic-bezier(0.25, 1, 0.5, 1);

// 主容器样式
.gallery-view {
  width: 100%;
  max-width: @container-width;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  min-height: 80vh;

  // 页面标题区域
  &__header {
    margin-bottom: 22px;
    animation: fadeInDown 0.5s @transition-ease;
  }

  // 过滤器区域
  &__filters {
    margin-bottom: 32px;
    animation: fadeIn 0.6s @transition-ease;
    border-radius: 14px;
    transition: all @transition-time;

    // 悬停效果
    &:hover {
      transform: translateY(-2px);
    }
  }

  // 主内容区域
  &__main {
    flex: 1;
    animation: fadeInUp 0.7s @transition-ease;
    transition: all @transition-time;
    padding-bottom: 40px;
    width: 100%;
  }
}

// 页面入场动画
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 响应式样式
@media (max-width: 1200px) {
  .gallery-view {
    padding: 0 20px;
    max-width: 100%;

    &__filters {
      margin-bottom: 28px;
    }

    &__main {
      padding-bottom: 32px;
    }
  }
}

@media (max-width: 992px) {
  .gallery-view {
    padding: 0 16px;

    &__header {
      margin-bottom: 18px;
    }

    &__filters {
      margin-bottom: 24px;

      &:hover {
        transform: none; // 在平板上禁用悬停效果
      }
    }
  }
}

@media (max-width: 768px) {
  .gallery-view {
    padding: 0 14px;

    &__header {
      margin-bottom: 14px;
    }

    &__filters {
      margin-bottom: 20px;
    }

    &__main {
      padding-bottom: 24px;
    }
  }
}

@media (max-width: 576px) {
  .gallery-view {
    padding: 0 12px;

    &__header {
      margin-bottom: 12px;
    }

    &__filters {
      margin-bottom: 16px;
    }

    &__main {
      padding-bottom: 20px;
    }
  }
}

// 优化子组件在容器中的表现
:deep(.yk-space) {
  width: 100%;

  &.yk-space--vertical .yk-space-item {
    width: 100%;
    margin-bottom: 0;
  }
}

// 改进顶部标题组件样式
:deep(.top-title) {
  padding-bottom: 6px;
  position: relative;

  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 80px;
    height: 3px;
    background: linear-gradient(to right, @primary-color, lighten(@primary-color, 25%));
    border-radius: 3px;
    transition: width 0.4s @transition-ease;
  }

  &:hover::after {
    width: 120px;
  }
}

// 过渡动画
.query-enter-active,
.query-leave-active {
  transition: opacity 0.3s ease;
}

.query-enter-from,
.query-leave-to {
  opacity: 0;
}
</style>
